package gold.digger;

import gold.utils.InputUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC775 {
    public long startExecuteTime = System.currentTimeMillis();


    /*
     * @param 此题目参考了别人代码
     * 不是因为复杂，而是因为经典
     * 未来需要再次复习此道题目
     * 挺有意思的数学题
     * @return:
     */
    class Solution {
        public boolean isIdealPermutation(int[] nums) {
            for (int i = 0; i < nums.length; i++) {
                if (Math.abs(nums[i] - i) > 1) return false;
            }

            return true;
        }
    }

    class Solution_Brute_Force {
        public boolean isIdealPermutation(int[] nums) {
            for (int i = 0; i < nums.length - 1; i++) {
                for (int j = i + 2; j < nums.length; j++) {
                    if (nums[j] < nums[i]) return false;
                }
            }

            return true;
        }
    }

    public void run() {
        Solution solution = new Solution();
        final int[] arr = InputUtil.toIntegerArray("[2,0,1]");
        System.out.println(solution.isIdealPermutation(arr));
    }

    public static void main(String[] args) throws Exception {
        LC775 an = new LC775();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
